<?php

class OperationController extends AdminController
{
    public function indexAction()
    {
        $do = $this->get('do');
        switch ($do) {
            case 'list':
                $this->operation_log('行为日志');
                $parameters['conditions'] = ['isdo' => 1];
                $parameters['order'] = 'id desc';

                $username = $this->get('username');
                $uri = $this->get('uri');
                $start_time = $this->get('start_time');
                $end_time = $this->get('end_time');

                if ($username) $parameters['conditions']['username'] = $username;
                if ($uri) $parameters['conditions']['operation_title'] = $uri;
                if ($start_time) $parameters['conditions'][] = ['time', '>=', strtotime($start_time)];
                if ($end_time) $parameters['conditions'][] = ['time', '<=', strtotime($end_time)];

                $data = $this->_list(AdminOperationLogsModel::class, $parameters);
                // 翻页
                foreach ($data['data'] as $item) {
                    $data_result[] = array(
                        'id' => $item->id,
                        'username' => $item->username,
                        'title' => $item->operation_title,
                        'uri' => $item->uri,
                        'time' => date('Y-m-d H:i:s', $item->time),
                    );
                }
                $this->ajaxresult(0, '', $data_result, array('count' => $data['count']));
                break;
        }
        // 加载所有分类
        $uris = AdminOperationLogsModel::group('operation_title')->field('operation_title')->select();
//        var_export($uris);
        $this->view->assign('uris', $uris);
    }

    function profileAction()
    {
        $id = $this->get('id');
        $data = AdminOperationLogsModel::find($id);
        if (!$data) $this->displayWarn('未找到您要查看的信息');
        $this->view->assign('data', $data);
    }

}
